<?php
    require  "../init.php";

    if(empty($_SESSION['admin'])){
        admin_redirect("请登录",3,ADMIN_ROOT_URL . "login.php");
        die;
    }

    //分页查找跳转的地址
    $url = "./index.php";

    $ordernum = '';
    $where = '';
    $urlname = '';
    if(isset($_GET['ordernum']) && !empty($_GET['ordernum'])){
        $ordernum = $_GET['ordernum'];
        $where = " where ordernum like '%$ordernum%'";
        $urlname = "&ordernum=$ordernum";
    }

    //得到要显示的数据的总条数
    $sql = "select count(*) as total from " .PRE . "order" .$where;
    $result = query($link, $sql);
    $total = $result[0]['total'];

    //每页显示的记录数
    //$num = PAGE_NUM;//
    $num = 5;

    //总页数 = ceil(总条数 / 总页数)
    $total_page = ceil($total / $num);

    //当前页码
    $page = isset($_GET['page']) ? (int)$_GET['page'] : 1;

    //限制页码的范围 (1,$total_page)
    // 如果页码0小于1,则$min=1;1 < $total_page(总页数),则$page=1
    // 如果页码10大于$total_page,则$min=10;10 > $total_page(总页数),则$page=$total_page
    $min = max(1, $page);
    $page = min($min, $total_page);

    //获取偏移量 (当前页码 - 1) * 每页的显示量
    $offset = ($page - 1) * $num;

    //上一页和下一页的页码
    $prev = $page - 1;
    $next = $page + 1;

    //制作数字页码
    $num_link = '';

    //制作数字页码的开始与结束
    $start = $page - 2;
    $end = $page + 2;

    //限制开始与结束页码
    $start = max(1, $start);
    $end = min($total_page, $end);

    for($i = $start; $i <= $end; $i++){
        if($page == $i){
            $num_link .= '<li class="active"><a href="./index.php?page='.$i.$urlname.'" >'.$i.'</a></li>';
            continue;
        }
        $num_link .= '<li><a href="./index.php?page='.$i.$urlname.'" >'.$i.'</a></li>';
    }

    //准备sql语句
    $sql = "select * from ".PRE . "order".
        $where ." limit  $offset,$num";

    //执行sql语句
    $result = query($link, $sql);

    //获取受影响行数,也就是每页的记录数
    $row = mysqli_affected_rows($link);



    //处理结果集
    mysqli_close($link);
?>

<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
    <meta name="author" content="GeeksLabs">
    <meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
    <link rel="icon" href="../../public/admin/img/icons/logo.jpg">

    <title>小米 后台(后台管理员)</title>

    <!-- Bootstrap CSS -->
    <link href="../../public/admin/css/bootstrap.min.css" rel="stylesheet">
    <!-- bootstrap theme -->
    <link href="../../public/admin/css/bootstrap-theme.css" rel="stylesheet">
    <!--external css-->
    <!-- font icon -->
    <link href="../../public/admin/css/elegant-icons-style.css" rel="stylesheet" />
    <link href="../../public/admin/css/font-awesome.min.css" rel="stylesheet" />
    <!-- full calendar css-->
    <link href="../../public/admin/assets/fullcalendar/fullcalendar/bootstrap-fullcalendar.css" rel="stylesheet" />
    <link href="../../public/admin/assets/fullcalendar/fullcalendar/fullcalendar.css" rel="stylesheet" />
    <!-- easy pie chart-->
    <link href="../../public/admin/assets/jquery-easy-pie-chart/jquery.easy-pie-chart.css" rel="stylesheet" type="text/css" media="screen"/>
    <!-- owl carousel -->
    <link rel="stylesheet" href="../../public/admin/css/owl.carousel.css" type="text/css">
    <link href="../../public/admin/css/jquery-jvectormap-1.2.2.css" rel="stylesheet">
    <!-- Custom styles -->
    <link rel="stylesheet" href="../../public/admin/css/fullcalendar.css">
    <link href="../../public/admin/css/widgets.css" rel="stylesheet">
    <link href="../../public/admin/css/style.css" rel="stylesheet">
    <link href="../../public/admin/css/style-responsive.css" rel="stylesheet" />
    <link href="../../public/admin/css/xcharts.min.css" rel=" stylesheet">
    <link href="../../public/admin/css/jquery-ui-1.10.4.min.css" rel="stylesheet">
    <link href="../../public/admin/css/index.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 -->
    <!--[if lt IE 9]>
    <script src="../../public/admin/js/html5shiv.js"></script>
    <script src="../../public/admin/js/respond.min.js"></script>
    <script src="../../public/admin/js/lte-ie7.js"></script>
    <![endif]-->
</head>

<body>
<!-- container section start -->
<section id="container" class="">
    <!--引入头部-->
    <?php require '../top.php'?>
    <!--引入左边菜单栏-->
    <?php require '../aside.php'?>

    <!--main content start-->
    <section id="main-content">
        <section class="wrapper">
            <!-- page start-->
            <div class="row">
                <div class="col-lg-12">
                    <section class="panel">
                        <header class="panel-heading">
                            管理员列表
                            <form class="navbar-form navbar-right" role="search" action="">
                                <div class="form-group">
                                    <input type="text" class="form-control" name="ordernum" placeholder="订单编号">
                                </div>
                                <button type="submit" class="btn btn-default">搜索</button>
                            </form>
                        </header>
                        <?php if(!empty($result)):?>
                            <table class="table table-striped table-advance table-hover">
                                <tbody>
                                <tr>
                                    <th class="text-center"><i class="icon_profile"></i> ID</th>
                                    <th class="text-center"><i class="icon_profile"></i> 订单编号</th>
                                    <th class="text-center"><i class="icon_mobile"></i> 用户ID</th>
                                    <th class="text-center"><i class="icon_mail_alt"></i> 收件人</th>
                                    <th class="text-center"><i class="icon_mail_alt"></i> 电话</th>
                                    <th class="text-center"><i class="icon_mail_alt"></i> 地址</th>
                                    <th class="text-center"><i class="icon_mail_alt"></i> 实付金额</th>
                                    <th class="text-center"><i class="icon_mail_alt"></i> 订单状态</th>
                                    <th class="text-center"><i class="icon_calendar"></i> 创建时间</th>
                                    <th class="text-center"><i class="icon_calendar"></i> 修改时间</th>
                                    <th class="text-center"><i class="icon_cogs"></i> Action</th>
                                </tr>

                                <?php foreach($result as $key => $value):?>
                                    <tr>
                                        <td class="text-center"><?php echo $value['id']?></td>
                                        <td class="text-center"><?php echo $value['ordernum']?></td>
                                        <td class="text-center"><?php echo $value['user_id']?></td>
                                        <td class="text-center"><?php echo $value['oname']?></td>
                                        <td class="text-center"><?php echo $value['phone']?></td>
                                        <td class="text-center"><?php echo $value['address']?></td>
                                        <td class="text-center"><?php echo $value['allprice']?></td>
                                        <td class="text-center">
                                            <?php echo $value['shipping_status']==0?"未确认":"已确认";?><br>
                                            <?php echo $value['pay_status']==0?"未付款":"已付款";?><br>
                                            <?php
                                            switch($value['order_status']){
                                                case 0: echo "未发货"; break;
                                                case 1: echo "已发货"; break;
                                                case 2: echo "已完成"; break;
                                                case 3: echo "已失效"; break;
                                            }
                                            ?>
                                        </td>
                                        <td class="text-center"><?php echo $value['create_time']?></td>
                                        <td class="text-center"><?php echo $value['update_time']?></td>

                                        <td class="text-center">
                                            <div class="btn-group">
                                                <a  href="<?php echo ADMIN_ROOT_URL?>order/order_details.php?id=<?php echo $value['id'];?>">查看详情</a>
                                                <br>
                                                <!--如果该订单未发货是,就显示发货链接-->
                                                <?php if($value['order_status'] == 0):?>
                                                    <a  href="<?php echo ADMIN_ROOT_URL?>order/action.php?act=send&id=<?php echo $value['id'];?>&pay_status=<?php echo $value['pay_status'];?>">发货</a>
                                                <?php endif;?>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endforeach;?>
                                </tbody>
                            </table>
                        <?php endif;?>

                        <!--分页开始-->
                        <?php require ADMIN_ROOT_PATH . "../com/page.php"?>
                        <!--分页结束-->
                    </section>
                </div>
            </div>
            <!-- page end-->
        </section>
    </section>
    <!--main content end-->

</section>
<!-- container section start -->

<!-- javascripts -->
<script src="../../public/admin/js/jquery.js"></script>
<script src="../../public/admin/js/jquery-ui-1.10.4.min.js"></script>
<script src="../../public/admin/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../../public/admin/js/jquery-ui-1.9.2.custom.min.js"></script>
<!-- bootstrap -->
<script src="../../public/admin/js/bootstrap.min.js"></script>
<!-- nice scroll -->
<script src="../../public/admin/js/jquery.scrollTo.min.js"></script>
<script src="../../public/admin/js/jquery.nicescroll.js" type="text/javascript"></script>
<!-- charts scripts -->
<script src="../../public/admin/assets/jquery-knob/js/jquery.knob.js"></script>
<script src="../../public/admin/js/jquery.sparkline.js" type="text/javascript"></script>
<script src="../../public/admin/assets/jquery-easy-pie-chart/jquery.easy-pie-chart.js"></script>
<script src="../../public/admin/js/owl.carousel.js" ></script>
<!-- jQuery full calendar -->
<<script src="../../public/admin/js/fullcalendar.min.js"></script> <!-- Full Google Calendar - Calendar -->
<script src="../../public/admin/assets/fullcalendar/fullcalendar/fullcalendar.js"></script>
<!--script for this page only-->
<script src="../../public/admin/js/calendar-custom.js"></script>
<script src="../../public/admin/js/jquery.rateit.min.js"></script>
<!-- custom select -->
<script src="../../public/admin/js/jquery.customSelect.min.js" ></script>
<script src="../../public/admin/assets/chart-master/Chart.js"></script>

<!--custome script for all page-->
<script src="../../public/admin/js/scripts.js"></script>
<!-- custom script for this page-->
<script src="../../public/admin/js/sparkline-chart.js"></script>
<script src="../../public/admin/js/easy-pie-chart.js"></script>
<script src="../../public/admin/js/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../../public/admin/js/jquery-jvectormap-world-mill-en.js"></script>
<script src="../../public/admin/js/xcharts.min.js"></script>
<script src="../../public/admin/js/jquery.autosize.min.js"></script>
<script src="../../public/admin/js/jquery.placeholder.min.js"></script>
<script src="../../public/admin/js/gdp-data.js"></script>
<script src="../../public/admin/js/morris.min.js"></script>
<script src="../../public/admin/js/sparklines.js"></script>
<script src="../../public/admin/js/charts.js"></script>
<script src="../../public/admin/js/jquery.slimscroll.min.js"></script>
<script>

    //knob
    $(function() {
        $(".knob").knob({
            'draw' : function () {
                $(this.i).val(this.cv + '%')
            }
        })
    });

    //carousel
    $(document).ready(function() {
        $("#owl-slider").owlCarousel({
            navigation : true,
            slideSpeed : 300,
            paginationSpeed : 400,
            singleItem : true

        });
    });

    //custom select box

    $(function(){
        $('select.styled').customSelect();
    });

    /* ---------- Map ---------- */
    $(function(){
        $('#map').vectorMap({
            map: 'world_mill_en',
            series: {
                regions: [{
                    values: gdpData,
                    scale: ['#000', '#000'],
                    normalizeFunction: 'polynomial'
                }]
            },
            backgroundColor: '#eef3f7',
            onLabelShow: function(e, el, code){
                el.html(el.html()+' (GDP - '+gdpData[code]+')');
            }
        });
    });



</script>

</body>
</html>